import java.util.HashMap;
import java.util.Random;

public class RandomizedSet {
    public int[] array;
    public int usedSize;
    Random random;
    HashMap<Integer,Integer> map;
    public RandomizedSet() {
        array=new int[100006];
        map=new HashMap<>();
        random=new Random();
        usedSize=-1;
    }
    public boolean insert(int val) {
        if(map.containsKey(val)){
            return false;
        }
        array[++usedSize]=val;
        map.put(val,usedSize);

        return true;
    }
    public boolean remove(int val) {
        if(!map.containsKey(val)){
            return false;
        }
        int loc=map.remove(val);
        if(loc!=usedSize){
            map.put(array[usedSize],loc);
        }
        array[loc]=array[usedSize--];
        return true;
    }
    public int getRandom() {
        return array[random.nextInt(usedSize+1)];
    }
}
